import { request } from '@/utils/http';

const LOGINBYWX = 'weixin/login';
const LOGIN = 'users/login';
const LOGIN_OUT = 'users/logout';
const REFRESH_TOKEN = '/refresh/token';

/**
 * 登录
 * @param params
 */
export function login(params: LoginParams) {
  return request.post<API<LoginModel>>(LOGIN, params, {
    custom: {
      auth: false,
    },
    headers: {
      'x-app-sources': 'pc',
    },
  });
}

/**
 * 微信一键登录
 */
export function loginByWx(params: LoginParams) {
  return request.post<API<LoginModel>>(LOGINBYWX, params, {
    custom: {
      auth: false,
    },
  });
}

/**
 * 登出
 */
export function logout() {
  return request.post<API>(
    LOGIN_OUT,
    {},
    {
      withCredentials: true,
    },
  );
}

/**
 * 刷新token
 */
export function refreshToken() {
  return request.post<API<LoginModel>>(REFRESH_TOKEN, {});
}
